﻿<?php
function sendSMS($mobile,$content)
{
	$post_data = array();
	$post_data['userid'] = 767;
	$post_data['account'] = "美沃通讯";       
	$post_data['password'] = 'mw123456';   
	$post_data['content'] = $content."【美沃通讯】";
	$post_data['mobile'] = $mobile; 
	$post_data['sendtime'] = '';
	$url='http://218.244.136.70:8888/sms.aspx';
	$o='action=send&';
	foreach ($post_data as $k=>$v) { $o.="$k=".urlencode($v).'&'; }
	$post_data=substr($o,0,-1);
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_URL,$url);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	$result = curl_exec($ch);
	curl_close($ch);
	$result =  simplexml_load_string($result);
	 if($result->returnstatus == 'Success'){
	 	return 100;
	 }else{
	 	return -1;
	 }
}


function sendSMS201606($mobile,$content)
{
	$http = 'http://api.sms.cn/tx/';		//短信接口
	$uid = '312000001';							//用户账号
	$pwd = 'dongqingyu';							//密码
	$mobileids	 = $mobile.'12345666688';	//号码唯一编号
	$data = array
		(
		'uid'=>$uid,					//用户账号
		'pwd'=>md5($pwd.$uid),			//MD5位32密码,密码和用户名拼接字符
		'mobile'=>$mobile,				//号码
		'content'=>$content,			//内容
		'mobileids'=>$mobileids,
		'encode' => 'utf8',
		'time'=>$time  //定时发送
		);
	$re= postSMS($http,$data);			//POST方式提交
	return $re;
}

function postSMS($url,$data='')
{
	$post ='';
	$row = parse_url($url);
	$row['port'] ='';
	$host = $row['host'];
	$port = $row['port'] ? $row['port']:80;
	$file = $row['path'];
	while (list($k,$v) = each($data)) 
	{
		$post .= rawurlencode($k)."=".rawurlencode($v)."&";	//转URL标准码
	}
	$post = substr( $post , 0 , -1 );
	$len = strlen($post);
	$fp = @fsockopen( $host ,$port, $errno, $errstr, 10);
	if (!$fp) {
		return "$errstr ($errno)\n";
	} else {
		$receive = '';
		$out = "POST $file HTTP/1.1\r\n";
		$out .= "Host: $host\r\n";
		$out .= "Content-type: application/x-www-form-urlencoded\r\n";
		$out .= "Connection: Close\r\n";
		$out .= "Content-Length: $len\r\n\r\n";
		$out .= $post;		
		fwrite($fp, $out);
		while (!feof($fp)) {
			$receive .= fgets($fp, 128);
		}
		fclose($fp);
		$receive = explode("\r\n\r\n",$receive);
		unset($receive[0]);
		return implode("",$receive);
	}
}
?>